<?php

namespace App\Http\Controllers\Admin\View;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Facades\Services\UserService;
use App\Facades\Services\RoleService;
use ValiDate;

class UserController extends Controller
{
    public function index(Request $request){

    	return view('pages.admin.user.list',[
    		'users' => UserService::getUsers()
    	]);
    }

    public function update(Request $request){

    	$rules = [
    		'id' => 'required|exists:users,id'
    	];

    	ValiDate::valiDate($request,$rules);

    	return view('pages.admin.user.update',[
    		'user' => UserService::getUser($request->id),
    		'roles' => RoleService::getRoles()
    	]);
    }

    public function create(Request $request){
    	return view('pages.admin.user.create',[
    		'roles' => RoleService::getRoles()
    	]);
    }
    public function details(Request $request){
    	$rules = [
    		'id' => 'required|exists:users,id'
    	];

    	ValiDate::valiDate($request,$rules);

    	return view('pages.admin.user.details',[
    		'user' => UserService::getUser($request->id)
    	]);
    }
}
